package com.fruit.web.vo.manage.goods;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.faces.application.FacesMessage;
import javax.faces.model.SelectItem;

import net.sf.cglib.beans.BeanCopier;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import org.richfaces.component.UIDataTable;
import com.fruit.service.ICategoryService;
import com.fruit.service.IGoodsService;
import com.fruit.service.IProductUnitService;
import com.fruit.service.IStakeholderService;
import com.fruit.service.IFruitCategoryService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.utils.UIComponentUtil;
import com.fruit.utils.ValidatorUtil;
import com.fruit.web.bo.impl.Category;
import com.fruit.web.bo.impl.Goods;
import com.fruit.web.bo.impl.Productunit;
import com.fruit.web.bo.impl.Stakeholder;
import com.fruit.web.bo.impl.FruitCategory;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.ManageBeanConstants;
import com.fruit.web.constant.SpringBeanConstants;
import com.fruit.web.vo.common.GoodsVo;
import com.fruit.web.vo.genl.ExistFruitCategoryBean;

public class UpdateGoodsPageBean extends GoodsCrudBean implements java.io.Serializable{

	private static final long serialVersionUID = 5054087821033164852L;
	//create or update shoes properties

	//end
	public UpdateGoodsPageBean(){
		
	}

	
	/*public String saveGoods() {
		this.setDisplayMessage(null);
		IGoodsService<Goods,Long> goodsService = (IGoodsService<Goods,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.GOODS_SERVICE_BEAN_NAME);
		goodsService.setEntityClass(Goods.class);
		goodsService.setPKClass(Long.class);
		boolean hasGoods = goodsService.ifExistBy("code", this.getGoods().getCode().trim());
		if (hasGoods) {
			String message = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,"operate.save.fail.hasexist.display", FacesMessage.SEVERITY_ERROR).getDetail();
			this.setDisplayMessage(message);
			return null;
		}
		validateGoods(this.getGoods(),this.getErrorMessages());
		if (!(this.getErrorMessages().isEmpty())) {
			return null;
		}
		Goods goods = new Goods();
		BeanCopier copyHere = BeanCopier.create(GoodsVo.class,Goods.class,false);
		copyHere.copy(this.getGoods(), goods, null);
		//start set product unit
		IProductUnitService<Productunit,Long> productUnitService = (IProductUnitService<Productunit,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.PRODUCTUNIT_SERVICE_BEAN_NAME);
		productUnitService.setEntityClass(Productunit.class);
		productUnitService.setPKClass(Long.class);
		Productunit theUnit = productUnitService.findUniqueBy("unitId", this.getGoods().getUnitv().getUnitId());
		goods.setUnit(theUnit);
		//end set product unit
		//start set stake holder
		IStakeholderService<Stakeholder,Long> stakeholderService = (IStakeholderService<Stakeholder,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.STAKEHOLDER_SERVICE_BEAN_NAME);
		stakeholderService.setEntityClass(Stakeholder.class);
		stakeholderService.setPKClass(Long.class);
		Stakeholder theStakeholder = stakeholderService.findUniqueBy("stakeholderId", this.getGoods().getProviderv().getStakeholderId());
		goods.setProvider(theStakeholder);
		//end set stake holder
		//start set properties
		List<GoodsPropertiesVo> tempGoodsProperties = this.getGoods().getPropertiesv();
		if (null != tempGoodsProperties && !(tempGoodsProperties.isEmpty())) {
			Set<GoodsProperties> properties = new HashSet<GoodsProperties>();
			BeanCopier copyIn = BeanCopier.create(GoodsPropertiesVo.class, GoodsProperties.class, false);
			for (GoodsPropertiesVo propertiesVo:tempGoodsProperties) {
				GoodsProperties tempProperties = new GoodsProperties();
				copyIn.copy(propertiesVo, tempProperties, null);
				properties.add(tempProperties);
			}
			goods.setProperties(properties);
		}
		//end set properties
		
		goodsService.save(goods);
		String message = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,"operate.save.success.display", FacesMessage.SEVERITY_ERROR).getDetail();
		this.setDisplayMessage(message);
		
		return null;
	}*/
	
}
